﻿using System;
using System.Linq;
using Stimulus360.Models.Common;
using System.Collections.Generic;

namespace Stimulus360.Models.Data
{
    /// <summary>
    ///     This is a partial class for the Idea entity to add custom functionality.
    /// </summary>
    public partial class Idea
    {
        /// <summary>
        ///     Boolean indicating if there are any rule voilations in the Idea
        ///     definition
        /// </summary>
        public bool IsValid
        {
            get { return (GetRuleViolations().Count() == 0); }
        }

        /// <summary>
        ///     Method to get the list of Rule Voilations for the current
        ///     Idea instance
        /// </summary>
        /// <returns>
        ///     List of RuleVoilations if any
        /// </returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", 
            Justification = "Method use is appropriate considering complexity and logic http://msdn.microsoft.com/en-us/library/bzwdh01d(VS.71).aspx#cpconpropertyusageguidelinesanchor1")]
        public IEnumerable<RuleViolation> GetRuleViolations()
        {
            if (String.IsNullOrEmpty(Title))
                yield return new RuleViolation(Resources.Stimulus360.Rule_IdeaTitle, "Title");

            if( string.IsNullOrEmpty(Description))
                yield return new RuleViolation(Resources.Stimulus360.Rule_IdeaDescription, "Description");

            if (CategoryId == 0)
                yield return new RuleViolation(Resources.Stimulus360.Rule_IdeaCategory, "CategoryId");
            
            yield break;
        }

       
        /// <summary>
        ///     String representing the Status Enum for the Idea.
        /// </summary>
        public  string StatusString
        {
            get
            {
                return ((IdeaStatus)Status).ToString();
            }
        }
    }
}
